import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import { visualizer } from 'rollup-plugin-visualizer'
import viteCompression from 'vite-plugin-compression';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue(),
    viteCompression({
      algorithm: 'gzip',      // 压缩算法，默认 'gzip':ml-citation{ref="3" data="citationList"}
      ext: '.gz',            // 压缩文件后缀:ml-citation{ref="2,3" data="citationList"}
      threshold: 10240,      // 仅压缩 >10KB 的文件（单位：字节）:ml-citation{ref="1,3" data="citationList"}
      verbose: true,         // 控制台输出压缩详情:ml-citation{ref="1,4" data="citationList"}
      deleteOriginFile: false // 是否删除源文件（生产环境慎用）:ml-citation{ref="3,4" data="citationList"}
    }),
    visualizer({
      open: true,         // 自动打开分析页面
      filename: 'stats.html',  // 输出文件名
      gzipSize: true,     // 显示gzip压缩后大小
      brotliSize: true    // 显示brotli压缩后大小
    })
  ],
  server: {
    port: 8080
  },
  esbuild: {
    drop: ['console', 'debugger'], // 同时移除debugger和console
  },
  build: {
    outDir: "blogdist",
    sourcemap: false,
    rollupOptions: {
      external: ['vue', 'pinia', 'vue-router', 'axios', 'video.js'],
      output: {
        globals: {
          vue: 'Vue',
          'pinia': 'Pinia',
          axios: 'axios',
          'vue-router': 'VueRouter',
          'video.js': 'video.js'
        }
      }
    }
  },
  define: {  
    'process.env': {
      BASE_URL: ''  
    }  
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@import "@/css/comment/base.scss";`
      }
    }
  },
  resolve: {
    extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'],
    alias: {
      '@components': path.resolve(__dirname, './src/components'),
      '@utils': path.resolve(__dirname, './src/utils'),
      '@': path.resolve(__dirname, './src')
    }
  }
})
